package com.qianlou.common.result;

import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 分页查询结果集
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PagedResult {
	
	private int page;			// 当前页数
	private long total;			// 总页数
	private long records;		// 总记录数
	private List<?> rows;		// 每行显示的内容


	public static PagedResult of(List<?> list,
										   Integer page) {
		PageInfo<?> pageList = new PageInfo<>(list);
		PagedResult gridResult = new PagedResult();
		gridResult.setRows(list);
		gridResult.setPage(page);
		gridResult.setRecords(pageList.getTotal());
		gridResult.setTotal(pageList.getPages());
		return gridResult;
	}

}
